using System;
using System.Xml;


using Microsoft.Services.TfsAlert.Core;

namespace Microsoft.Services.TfsAlert.AppCode.NotificationEvents
{
    public class NotificationEventFactory
    {
        public INotificationEvent CreateEvent( string eventXML )
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml( eventXML );

            ApplicationHelpers applicationHelpers = new ApplicationHelpers();

            switch( xmlDocument.DocumentElement.Name )
            {
                case "CheckinEvent":
                    return applicationHelpers.DeserializeXml<CheckinEvent>(xmlDocument);
                  
                case "DataChangedEvent":
                    return applicationHelpers.DeserializeXml<DataChangedEvent>(xmlDocument);
                    
                case "AclChangedEvent":
                    return applicationHelpers.DeserializeXml<AclChangedEvent>( xmlDocument );

                case "BranchMovedEvent":
                    return applicationHelpers.DeserializeXml<BranchMovedEvent>( xmlDocument );

                case "BuildCompletionEvent":
                    return applicationHelpers.DeserializeXml<BuildCompletionEvent>( xmlDocument );

                case "BuildStatusChangeEvent":
                    return applicationHelpers.DeserializeXml<BuildStatusChangeEvent>( xmlDocument );

                case "MembershipChangedEvent":
                    return applicationHelpers.DeserializeXml<MembershipChangedEvent>( xmlDocument );

                case "WorkItemChangedEvent":
                    return applicationHelpers.DeserializeXml<WorkItemChangedEvent>( xmlDocument );

                default:
                    throw new ApplicationException( "Invalid WorkItem Type Passed" );
            }
        }
    }
}